<template>
    <div>
        <div class="seach">
            <span class="seachStatus">
                {{$t('tsknum')}}
                <el-input v-model.trim="merList.orderNo" :placeholder="$t('plsset')" size="mini"></el-input>
            </span>
            <span>
                {{$t('audsta')}}
                <el-select v-model="merList.auditStatus" :placeholder="$t('plsset')" size="mini">
                    <el-option :label="'-' + $t('plsset') + '-'" value=""></el-option>
                    <el-option :label="$t('tobeaud')" value="WAITCONFIRM"></el-option>
                    <el-option :label="$t('audpass')" value="SUCCESS"></el-option>
                    <el-option :label="$t('audfail')" value="ERROR"></el-option>
                </el-select>
            </span>
            <span class="seachStatus">
                {{$t('mertid')}}
                <el-input v-model.trim="merList.merId" :placeholder="$t('plsset')" size="mini"></el-input>
            </span>
            <span>
                {{$t('subttim')}}
                <el-date-picker :placeholder="$t('plsset')" v-model="applytime" width="20%" type="daterange" :range-separator="$t('to')" :start-placeholder="$t('startdate')" :end-placeholder="$t('dateclosed')" format="yyyy-MM-dd" value-format="yyyy-MM-dd" size="mini"></el-date-picker>
            </span>
            <el-button type="primary" @click="seachReg" size="mini" v-preventReClick>{{$t('qury')}}</el-button>
        </div>
        <!-- 内容区域 -->
        <el-card class="cardBox">
            <el-table border style="width: 100%" :data="orderTab" :row-class-name="tableRowClassName">
                <el-table-column type="index" :label="$t('sernum')">
                </el-table-column>
                <el-table-column prop="orderNo" :label="$t('tsknum')" min-width="199">
                </el-table-column>
                <el-table-column prop="merId" :label="$t('mertid')" min-width="198">
                </el-table-column>
                <el-table-column prop="merName" :label="$t('mertnam')" min-width="130">
                </el-table-column>
                <el-table-column prop="applyTime" :label="$t('subtim')" min-width="187">
                </el-table-column>
                <el-table-column prop="auditStatus" :label="$t('audsta')" min-width="101">
                </el-table-column>
                <el-table-column prop="proStatus" :label="$t('rstofaud')" min-width="136">
                </el-table-column>
                <el-table-column prop="auditUserName" :label="$t('audr')">
                </el-table-column>
                <el-table-column prop="address" :label="$t('opratn')" width="120" fixed="right">
                    <template slot-scope="scope">
                        <el-link type="primary" :disabled="scope.row.isAble" @click="Audit(scope.row)">{{$t('exme')}}</el-link>
                        <el-link type="primary" @click="View(scope.row)">{{$t('see')}}</el-link>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="merList.pageNum"
                :page-sizes="[10, 15, 20, 30]"
                :page-size="merList.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                :pager-count="5">
            </el-pagination>
        </el-card>
    </div>
</template>

<script>
import {
    merlist,
    meraudit
} from '@/libs/reqlist.js'
import { getInitDate } from '@/libs/getDate.js'
export default {
    data() {
        return {
            applytime: null,
            merList: {
                orderNo: null,
                auditStatus: 'WAITCONFIRM',
                name: null,
                startTime: null,
                endTime: null,
                merId: null,
                orderParamIdx: 0,
                orderType: null,
                applyTypeList: ['MER_REG'],
                pageNum: 1,
                pageSize: 10
            },
            total: 0,
            orderTab: [],
            recheck: {
                recordReqVos: null,
                orderNo: null,
                auditStatus: null,
                auditRemark: null,
                parentAuditId: null,
                productReqVos: null,
                productCode: null,
                rateType: null,
                rateValue: null,
                additionRateValue: null,
                takeEffectTime: null,
                loseEfficacyTime: null,
                applyTime: null,
                remark: null
            }
        }
    },
    methods: {
        async getmerList () {
            await merlist(JSON.stringify(this.merList)).then(res => {
                if (res.data.code === '000000') {
                    this.total = res.data.data.total - 0
                    this.orderTab = res.data.data.list
                    this.orderTab.forEach(item => {
                        if (item.auditStatus === 'WAITCONFIRM') {
                            item.auditStatus = this.$t('tobeaud')
                            item.isAble = false
                        }
                        if (item.auditStatus === 'SUCCESS') {
                            item.auditStatus = this.$t('audited')
                            item.proStatus = this.$t('audpass')
                            item.isAble = true
                        }
                        if (item.auditStatus === 'ERROR') {
                            item.auditStatus = this.$t('audited')
                            item.proStatus = this.$t('audfail')
                            item.isAble = true
                        }
                        if (item.auditStatus === 'TO_REVIEW') {
                            item.auditStatus = this.$t('tobereaud')
                            item.isAble = false
                        }
                        if (item.auditRemark === null) item.auditRemark = '/'
                    })
                }
            })
        },
        tableRowClassName({ row, rowIndex }) {
            if (row.auditStatus === this.$t('tobeaud') || row.auditStatus === this.$t('tobereaud')) {
                return 'warning-row'
            }
            return ''
        },
        // 监听页面展示数据条数变化
        handleSizeChange (newSize) {
            this.merList.pageSize = newSize
            this.getmerList()
        },
        // 监听总页数变化
        handleCurrentChange (newNum) {
            this.merList.pageNum = newNum
            window.localStorage.setItem('curpage', newNum)
            this.getmerList()
        },
        // 查询
        seachReg () {
            if (this.applytime !== null) {
                this.merList.startTime = this.applytime[0] + ' 00:00:00'
                this.merList.endTime = this.applytime[1] + ' 59:59:59'
            }
            if (this.applytime === null) {
                this.merList.startTime = null
                this.merList.endTime = null
            }
            this.merList.pageNum = 1
            this.getmerList()
        },
        Audit (item) {
            window.localStorage.setItem('merid', item.merId)
            meraudit(JSON.stringify({ parentOrderNo: item.orderNo })).then(res => {
                if (res.data.data === []) {
                    this.$message.error(this.$t('audinfmiss'))
                    return false
                }
                window.sessionStorage.setItem('handleOrder', item.orderNo)
                window.sessionStorage.setItem('orderSta', item.auditStatus)
                if (!res.data.data[1]) {
                    this.$message.error(this.$t('lackofauddata'))
                }
                if (res.data.data[1].applyData.merType === 'SMALL_MER') {
                    let extent = 3
                    if (res.data.data.length !== extent) this.$message.error(this.$t('lackofauddata'))
                    if (res.data.data.length === extent) {
                        window.sessionStorage.setItem('operate', 'review')
                        window.sessionStorage.setItem('size', 'small')
                        this.$router.push('/sec/lit/merAudit')
                    }
                }
                if (res.data.data[1].applyData.merType === 'BIG_MER') {
                    let extent = 5
                    if (res.data.data.length !== extent) this.$message.error(this.$t('lackofauddata'))
                    if (res.data.data.length === extent) {
                        window.sessionStorage.setItem('operate', 'review')
                        window.sessionStorage.setItem('size', 'big')
                        this.$router.push('/sec/big/merAudit')
                    }
                }
            })
        },
        View (item) {
            meraudit(JSON.stringify({ parentOrderNo: item.orderNo })).then(res => {
                window.sessionStorage.setItem('orderSta', item.auditStatus)
                window.sessionStorage.setItem('handleOrder', item.orderNo)
                if (!res.data.data[1]) {
                    this.$message.error(this.$t('lackofauddata'))
                }
                if (res.data.data[1].applyData.merType === 'SMALL_MER') {
                    let extent = 3
                    if (res.data.data.length !== extent) this.$message.error(this.$t('lackofauddata'))
                    if (res.data.data.length === extent) {
                        // examine查看
                        window.sessionStorage.setItem('operate', 'examine')
                        window.sessionStorage.setItem('size', 'small')
                        this.$router.push('/sec/lit/merAudit')
                    }
                }
                if (res.data.data[1].applyData.merType === 'BIG_MER') {
                    let extent = 5
                    if (res.data.data.length !== extent) this.$message.error(this.$t('lackofauddata'))
                    if (res.data.data.length === extent) {
                        window.sessionStorage.setItem('operate', 'examine')
                        window.sessionStorage.setItem('size', 'big')
                        this.$router.push('/sec/big/merAudit')
                    }
                }
            })
        }
    },
    mounted () {
        this.getmerList()
        window.sessionStorage.removeItem('step')
    },
    destroyed () {
        if (window.localStorage.getItem('curpage')) window.localStorage.removeItem('curpage')
    }
}
</script>

<style lang="less" scoped>
@import './merAud.less';
</style>
